package com.iris.live.services.data.repositories;

import com.iris.live.services.data.models.销售财务账目表Model;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by cyl on 2017/12/12.
 */
public interface 销售财务账目表Repository extends JpaRepository<销售财务账目表Model,Integer>,JpaSpecificationExecutor<销售财务账目表Model>{

    @Query("select a from 销售财务账目表Model a where a.订单编号 = ?1 and a.账目类型 = ?2 and a.是否红冲 = ?3 and a.发票项目 = '整车'")
    List<销售财务账目表Model> selectByOrderNumAndItemTypeAndIsRed(String orderNum,String itemType, String isRed);

    // 获取当前账目下的所有核销金额
    @Query(value = " SELECT IFNULL(SUM(a.账目金额),0) FROM 销售财务账目表 a WHERE a.关联编号= ?1  ",nativeQuery = true)
    String selectWriteMoney(Integer AccountId);

    //获取当前账目的挂账金额
    @Query(value = "SELECT a.账目金额 FROM 销售财务账目表 a  WHERE a.账目编号 = ?1 ",nativeQuery = true)
    String selectGuaMoney(Integer AccountId);

    @Query(value = "select a from 销售财务账目表Model a where a.账目类型 = '核销' and a.关联编号 = ?1 and a.是否红冲 = '0'")
    List<销售财务账目表Model> getWriteOfRecordOfBill(Integer financeDetailId);

}
